package com.whjz.dcfs.jzxx.struts.action;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.whjz.dcfs.jzxx.dao.IDcfsJcjgxxDao;
import com.whjz.dcfs.jzxx.model.DcfsJcjg;
import com.whjz.dcfs.util.BaseAction;

public class JZSBJCJGAction extends BaseAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Autowired
	public IDcfsJcjgxxDao iDcfsJcjgxxDao;
	
	public DcfsJcjg dcfsJcjg;
	
	/**
	 * 根据监测设备编号查询
	 * 查询监测结果值
	 * @throws Exception
	 */
	public void getDcfsJcjgListByCond() throws Exception{
		try{
			getHttpServletResponse().setCharacterEncoding("utf-8");
			List<DcfsJcjg> listall=iDcfsJcjgxxDao.getDcfJcjgByCond(dcfsJcjg);
			StringBuffer sb=new StringBuffer();
			sb.append("{jcjg:[");
			if(listall!=null&&listall.size()>0){
				for(int i=0;i<listall.size();i++){
					sb.append("{");
					sb.append("JZ_ID:'"+(listall.get(i).getJZ_ID()==null?"":listall.get(i).getJZ_ID())+"',");
					sb.append("JZ_BH:'"+(listall.get(i).getJZ_BH()==null?"":listall.get(i).getJZ_BH())+"',");
					sb.append("JZ_MC:'"+(listall.get(i).getJZ_MC()==null?"":listall.get(i).getJZ_MC())+"',");
					sb.append("JZ_FW:'"+(listall.get(i).getJZ_FW()==null?"":listall.get(i).getJZ_FW())+"',");
					sb.append("JZ_TXZXJL:'"+(listall.get(i).getJZ_TXZXJL()==null?"":listall.get(i).getJZ_TXZXJL())+"',");
					sb.append("JZ_TXSPJL:'"+(listall.get(i).getJZ_TXSPJL()==null?"":listall.get(i).getJZ_TXSPJL())+"',");
					sb.append("JZ_DCQD:'"+(listall.get(i).getJZ_DCQD()==null?"":listall.get(i).getJZ_DCQD())+"',");
					sb.append("GL_MD:'"+(listall.get(i).getGL_MD()==null?"":listall.get(i).getGL_MD())+"',");
					sb.append("}");
					
					if(i < listall.size()-1){
						sb.append(",");
					}
				}
			}
			sb.append("]}");
			getHttpServletResponse().getWriter().println(sb);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	/**
	 * 删除监测结果信息
	 * @throws Exception
	 */
	public void deleteDcfsJcjgByCond() throws Exception{
		try {
			getHttpServletResponse().setCharacterEncoding("utf-8");
			String[] ids=dcfsJcjg.getJZ_ID().split(",");
			List<DcfsJcjg> list=new ArrayList<DcfsJcjg>();
			DcfsJcjg object;
			for (String string : ids) {
				object=new DcfsJcjg();
				object.setJZ_ID(string);
				list.add(object);
			}
//			iDcfsJcjgxxDao.deleteDcfsJcjgByCond(dcfsJcjg);
			iDcfsJcjgxxDao.deleteDcfsJcjgListByCond(list);
			getHttpServletResponse().getWriter().println("{success:'true',msg:'删除成功'}");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 添加监测结果信息
	 * @throws Exception
	 */
	public void insertDcfsJcjgByCond() throws Exception{
		getHttpServletResponse().setCharacterEncoding("utf-8");
		dcfsJcjg.setJZ_ID(String.valueOf(System.currentTimeMillis()));
		iDcfsJcjgxxDao.insertDcfsJcjg(dcfsJcjg);
		getHttpServletResponse().getWriter().println("{success:'true',msg:'添加成功'}");
	}
	
	/**
	 * 修改监测结果信息
	 * @throws Exception
	 */
	public void updateDcfsJcjgByCond() throws Exception{
		getHttpServletResponse().setCharacterEncoding("utf-8");
		iDcfsJcjgxxDao.updateDcfsJcjgByCond(dcfsJcjg);
		getHttpServletResponse().getWriter().println("{success:'true',msg:'修改成功'}");
	}
	 
	public DcfsJcjg getDcfsJcjg() {
		return dcfsJcjg;
	}

	public void setDcfsJcjg(DcfsJcjg dcfsJcjg) {
		this.dcfsJcjg = dcfsJcjg;
	}

	
}
